package com.mtoolkit.logger;

import com.mtoolkit.util.StringUtil;

/**
 * A utility class that provides record logger conveniently.
 * 
 * @author 	<a href="mailto:xishizhang@gmail.com">ZhangShixi</a>
 * @version 1.0, 11/15/2012
 */
public final class Loggers {

    private Logger _logger;

    public Loggers(Logger logger) {
    	if (logger == null) {
    		throw new NullPointerException("logger");
    	}
    	
        this._logger = logger;
    }
    
    public static Loggers getLogger(Class<?> clazz) {
        return new Loggers(LoggerFactory.getLog(clazz));
    }
    
    public void trace(String message, Object... params) {
        if (message != null && _logger.isTraceEnabled()) {
            _logger.trace(StringUtil.replaceHolderArgs(message, params));
        }
    }
    
    public void debug(String message, Object... params) {
        if (message != null && _logger.isDebugEnabled()) {
            _logger.debug(StringUtil.replaceHolderArgs(message, params));
        }
    }
    
    public void info(String message, Object... params) {
        if (message != null && _logger.isInfoEnabled()) {
            _logger.info(StringUtil.replaceHolderArgs(message, params));
        }
    }
    
    public void warn(String message, Object... params) {
        if (message != null && _logger.isWarnEnabled()) {
            _logger.warn(StringUtil.replaceHolderArgs(message, params));
        }
    }
    
    public void error(String message, Object... params) {
        if (message != null && _logger.isErrorEnabled()) {
            _logger.error(StringUtil.replaceHolderArgs(message, params));
        }
    }
    
}
